﻿<%--
 *  File:    VisitPlanAddPopOneDay.jsp
 *  @Author: KentZhong 
 *  Date:    2009-10-9 10:02:44
 *
 *  Copyright (C) 2000 - 2009 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>
<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>


<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>


<%
  	String strTableName = "v_visitplancustomer";
  	String strModuleName = "SFE";
	String contextPath = request.getContextPath();
	java.util.HashMap userInfo = (java.util.HashMap)session.getAttribute("userinfo"); 
%>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>
<html>
<head>
<title>VisitPlanAddPopOneDay</title>
<%
if("Y".equals(request.getParameter("isconfirm"))){%>

<script>
	opener.refreshWindow();
</script>
<%return;
}%>	
<PageFlow:CheckPageFlow pageName="p_visitplanaddpop"/>
<%@ include file="/inc/SumDiv.inc" %>
<%
int nYear=((Integer)pageContext.getAttribute("year")).intValue();
int nMonth=((Integer)pageContext.getAttribute("monthofyear")).intValue();
int nWeek=((Integer)pageContext.getAttribute("weekofmonth")).intValue();
int nDay=((Integer)pageContext.getAttribute("dayofweek")).intValue();
//Date dStartDate=(Date)pageContext.getAttribute("weekstart");
//out.print(nDay);
Calendar cal=null;
if(nYear>0 && nMonth>0 && nWeek>0)
{
//	cal=Calendar.getInstance();
//	cal.clear();
//	cal.setTime(dStartDate);
//	cal.add(Calendar.DATE,nDay-1);
	cal=Calendar.getInstance();
	cal.clear();
	cal.setFirstDayOfWeek(Calendar.MONDAY);
	cal.set(Calendar.YEAR, nYear);
	cal.set(Calendar.MONTH, nMonth-1);
	cal.set(Calendar.WEEK_OF_MONTH, nWeek);
	cal.add(Calendar.DATE,nDay-1);
 }
 pageContext.setAttribute("year",new Integer(nYear));
 pageContext.setAttribute("monthofyear",new Integer(nMonth));
 pageContext.setAttribute("weekofmonth",new Integer(nWeek));
 
java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("yyyy-MM-dd");
String strVisitDate=sdf.format(cal.getTime());
java.text.SimpleDateFormat sdfVisit=new java.text.SimpleDateFormat((String)session.getAttribute("dateformat"));
String strVisitDateShow=sdfVisit.format(cal.getTime());
%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=contextPath%>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath%>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/ScriptLib.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/SummaryDivision.js"></script>
<script language="JavaScript">
<%--  put your custom script here   --%>
function page_summary(actionvalue,orderbyname)
{
  var editform = summaryPrepare(cform,actionvalue,orderbyname);
  if(!editform) return;
  editform.action = "VisitPlanAddPopOneDay.jsp?<%= OvalTools.randomURL() %>";
  editform.target = "_self";
  isRunning = true;
  editform.submit();
}
function page_cancel()
{
	window.close();
}
function page_confirm()
{
    //if(!checkForm(cform))   return;
	var myform = eval("document.cform");
	var details=eval("document.cform.customerids");
	
	
	if(isNullChecked(details))
  {
    alert("<%= message.getMessageDesc("PLEASE_SELECT") %>");
    return;
  }
  for(i=0;i<Number(myform.numrows.value);i++)
  {
  	var customer=eval("myform.customerid"+i);
  	var processid=eval("myform.processid"+i);
  	var uprocessid=eval("myform.uprocessid"+i);
  	var checkids=eval("myform.chkids"+i);
 	//var sstart=eval("myform.splanstarttime"+i);
	//	var send=eval("myform.splanendtime"+i);
	//	var tsstart=eval("myform.tsplanstarttime"+i);
	//	var tsend=eval("myform.tsplanendtime"+i);
		
		var dvisit=eval("myform.planvisitdate"+i);
		
  	if(!checkids.checked)
  	{
  		customer.value=" ";
  	}
  	else
  	{
  		<%--if(isEmpty(tsstart.value))
			{
				alert("<%=message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_VisitPlanStartTime"))%>");
				return;
			}
			if(isEmpty(tsend.value))
			{
				alert("<%=message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_VisitPlanEndTime"))%>");
				return;
			}
			if(!isTime(tsstart.value,"HH:mm"))
			{
				alert("<%=message.getMessageDesc("ILLEGAL_FORMAT",label.getLabelName("L_VisitPlanStartTime"))%>(HH:mm)");
				return;
			
			}
			if(!isTime(tsend.value,"HH:mm"))
			{
				alert("<%=message.getMessageDesc("ILLEGAL_FORMAT",label.getLabelName("L_VisitPlanEndTime"))%>(HH:mm)");
				return;
			
			}--%>
  		customer.value=checkids.value;
  		//alert(processid.value);
  		if(isEmpty(processid.value) && isEmpty(uprocessid.value)){
  		   alert("<%=message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_VisitProcess"))%>");
  		   return;
  		}
  		//sstart.value=dvisit.value+" "+tsstart.value+":00";
			//send.value=dvisit.value+" "+tsend.value+":00";
  	}

  }
   
    myform.actionname.value = "add";
 	myform.target="_self";
 	isRunning = true;
 	myform.submit();
}	
function selectvisitprocess(id){
var  datahandler = new  DataHandler() ;
datahandler.add_params("id" , id,"integer") ;
datahandler.add_params("languagecode" , 'cn',"string") ;
datahandler.getResultFromVector("vVectorSelect","processname" ,"visitprocessid" ,"document.cform.vVectorSelect") ;
datahandler.add_job("j_visitprocess") ;
datahandler.runDataHandler ();


}

function page_setUser(id,code,name){
	var rownum= document.cform.rownum.value;
	eval("document.cform.assistuserid"+rownum).value=id;
	eval("document.cform.assistemployeename"+rownum).value=name;
    }
function page_selectUser(num) {
        document.cform.rownum.value=num;
        //alert(eval("document.cform.assistuserid"+num).value);
		var status = "height=400, width=600,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no";
		var url = "<%=contextPath%>/sfe/UserSelectPop.jsp?businessareaid="+<%=userInfo.get("businessareaid")%>+"&contactid=<custom:write property="contactid"/>"+"&o_thread=" + Math.random();
			
		if (typeof popwindow != 'undefined') popwindow.close();
		popwindow = window.open(url, "newwindow2", status);
}
function showPasswordinfo(){
	var flag = '';
	if(flag){
		var div = document.getElementById('assistdiv');
		div.style.display = 'block';	
	}
}
function showPassword(){
	var isusesystem = document.frm.isusesystem.value;
	if(isusesystem == 'Y'){
		document.frm.isusesystemflag.checked = 'checked';
		setPasswordTable();
	}
}

function clickCheckBox(obj){
    //alert(cform.numrows.value);
	if(cform.numrows.value >= 1){
		var j=0;
		for(var i=0;i<Number(cform.numrows.value);i++){
			var idchk=document.getElementById('chkids'+j);
			if(idchk){
				idchk.checked=obj.checked;
			}
			j++;
		}
	}
}
function clearCheckFlag(obj){
	if(!obj.checked){
		cform.checkallbox.checked=false;
	}
}
</script>
</head>
<body style="overflow: auto;">
	<form name="cform" method="post" action="<%=contextPath%>/Dispatcher">
    <input type="hidden" name="pagename" value="p_visitplanaddpop">
    <input type="hidden" name="actionname">
    <custom:hidden property="contactid"/>
    <custom:hidden property="orgid" name="userinfo" scope="Session"/>
    <custom:hidden property="year"/>
    <custom:hidden property="monthofyear"/>
    <custom:hidden property="weekofmonth"/>
    <custom:hidden property="dayofweek"/>
    <custom:hidden property="ishistory"/>	
    <custom:hidden property="visitplanid" />
    <custom:hidden property="weekstart"/>
    <custom:hidden property="weekend" />	
    <custom:hidden property="weekstartweekofmonth" />	
    <input type="hidden" name="rownum">
    	<custom:hidden property="activitytype" />	
    	<custom:hidden property="plantype" />
    	<custom:hidden property="detailsstatus" />
    <input type="hidden" name="removedempty" value=" "/>	
   <table width="100%" cellspacing="0" border="0" cellpadding="0">
      <tr>
<%--  search criteria  --%>
      </tr>
      <tr>
        <td>
          
          <table width="100%" border="0" cellspacing="0">
           
            <%@ include file="/inc/SummarySearch.inc" %>
            
            
          </table>
        </td>
      </tr>
      <tr>
        <td>
        <%
        Vector vCustomers=(Vector)pageContext.getAttribute("customers");
  		if(vCustomers==null)
  			vCustomers=new Vector();
        %>
          <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
             <tr class="deepblue-left">  
          			<td class="title_center"  width="2%">
          			<%if(vCustomers.size() > 0){ %>
				      <input type="checkbox" name="checkallbox" class="checkbox"  onclick="clickCheckBox(this)">
			        <%}else{ %>
				      &nbsp;
			        <%} %>
                    </td>
          			<td class="title_center"  width="5%"><%=label.getLabelName("L_CustomerCode")%></td>
          			<td class="title_center"  width="22%"><%=label.getLabelName("L_CustomerName")%></td>
          			<td class="title_center"  width="6%"><%=label.getLabelName("L_GlobalPCName")%></td>
          			<td class="title_center"  width="10%"><%=label.getLabelName("L_CustomervisitProgram")%></td>
          			<td class="title_center"  width="10%"><%=label.getLabelName("L_PeoplevisitProgram")%></td>
          			<td class="title_center"  width="7%"><%=label.getLabelName("L_VisitPlanDate")%></td>
          			<td class="title_center"  width="7%"><%=label.getLabelName("L_LastVisitDate")%></td>
          			<td class="title_center"  width="5%"><%=label.getLabelName("L_CountVisitOfMonth")%></td>
          			<td class="title_center"  width="8%"><%=label.getLabelName("L_Dspotential")%></td>
          			<td class="title_center"  width="5%"><%=label.getLabelName("L_NeedAssist")%></td>
          			<td class="title_center"  width="4%"><%=label.getLabelName("L_Property")%></td>
          			<td class="title_center"  width="8%"><%=label.getLabelName("L_AssistUser")%></td>
          	</tr>
          	<%
          		String strClassType = "none";	
          		
          		Vector vAllprocesses=(Vector)pageContext.getAttribute("allprocesses");
          		if(vAllprocesses==null)
          			vAllprocesses=new Vector();
          		
          		
          	%>
          	 <logic:iterate id="customerinfo" collection="<%=vCustomers%>" indexId="idx">
          	 	<%
          	 	int seq=((Integer)pageContext.getAttribute("idx")).intValue();
          	 	 if(seq%2 == 1)
            {
              strClassType = "td-listrom";
            }else{
              strClassType = "none";
            }
          	 	
          	 	/* 
          	 	Vector vNewVector = new Vector();
          	 	Vector vVectorSelect = new Vector();
          	 	HashMap tempMap = (HashMap)pageContext.getAttribute("customerinfo");
          	 	Integer globalpccode = (Integer)tempMap.get("globalpccode"); 
          	 	String reserved1 = null;
          	 	//System.out.print("reserved1="+tempMap.get("reserved1"));
          	 	if(tempMap.get("reserved1")!=null){
          	 		reserved1 =  (String)tempMap.get("reserved1");
          	 	}
          	 	String reserved2 = null;
          	 	if(tempMap.get("reserved2")!=null){
          	 		reserved2 =  (String)tempMap.get("reserved2");
          	 	}
          	 	HashMap processesTempHash = new HashMap();
          	 	
          	 	for (int i = 0;i < vAllprocesses.size();i++) {
          	 		HashMap hm = new HashMap();
          	 		//System.out.println(vAllprocesses.get(i));
          	 		if(vAllprocesses.get(i) instanceof HashMap){
          	 			processesTempHash = (HashMap)vAllprocesses.get(i);
          	 			Integer tempglobalpccode = (Integer)processesTempHash.get("globalpccode");
          	 			String tempreserved1 = null;
          	 			if(processesTempHash.get("attribute1")!=null){
          	 				tempreserved1 = ((Integer)processesTempHash.get("attribute1")).toString();
          	 			}
          	 			String tempreserved2 = null;
          	 			if(processesTempHash.get("attribute2")!=null){
          	 				tempreserved2 = ((Integer)processesTempHash.get("attribute2")).toString();
          	 			}
          	 			//System.out.print("attribute1:"+reserved1);
          	 			 //System.out.print(globalpccode);
          	 			 //System.out.print(reserved1+" "+reserved2);
          	 			 System.out.print("reserved1:"+reserved1);
          	 			 System.out.print("reserved2:"+reserved2);
          	 			 System.out.print("tempreserved1:"+tempreserved1);
          	 			 System.out.print("tempreserved2:"+tempreserved2);
          	 			 //System.out.print(reserved1.indexOf(tempreserved1)=-1);
          	 			 //System.out.println((new Integer(-1)).equals(new Integer(-1)));
          	 	     if(tempglobalpccode==new Integer(112)){
          	 	    	if( (tempglobalpccode.equals(globalpccode)) && (reserved1.equals(tempreserved1) || tempreserved1==null) && (reserved2.equals(tempreserved2) || tempreserved2==null)){
          	 				//System.out.println(processesTempHash.get("processname")+","+globalpccode+","+reserved1+","+reserved2+"-------"+tempglobalpccode+","+tempreserved1+","+tempreserved2);
          	 				//privilegeSet.contains("MB-AQKC03")
          	 				hm.put("processname",processesTempHash.get("processname"));
          	 				hm.put("visitprocessid",processesTempHash.get("visitprocessid"));
          	 				vNewVector.add(hm);
          	 			}	 
          	 	     }else{
          	 			if( (tempglobalpccode.equals(globalpccode)) && (reserved1.equals(tempreserved1) || tempreserved1==null) && (reserved2.equals(tempreserved2) || tempreserved2==null)){
          	 				//System.out.println(processesTempHash.get("processname")+","+globalpccode+","+reserved1+","+reserved2+"-------"+tempglobalpccode+","+tempreserved1+","+tempreserved2);
          	 				//privilegeSet.contains("MB-AQKC03")
          	 				hm.put("processname",processesTempHash.get("processname"));
          	 				hm.put("visitprocessid",processesTempHash.get("visitprocessid"));
          	 				vNewVector.add(hm);
          	 			}
          	 	     }
          	 	            hm.put("processname",processesTempHash.get("processname"));
          	 				hm.put("visitprocessid",processesTempHash.get("visitprocessid"));
          	 				vNewVector.add(hm);
          	 		}
          	 	}
          	 	for(int i=0;i<vNewVector.size();i++){ 
          	 	    if(!vVectorSelect.contains(vNewVector.get(i)) )
          	 	    	 vVectorSelect.add(vNewVector.get(i)); 
          	 	}
          	 	pageContext.setAttribute("vVectorSelect",vVectorSelect);
          	 	*/
          	 	%>
          	 	<tr   class="<%=strClassType%>" >
	 					  	<td>
	 					  		<input type="checkbox" name="customerids" id="chkids<%=seq%>" value="<custom:write name="customerinfo" property="orgid"/>" class="normalradio" onclick="clearCheckFlag(this)"/>
	 					  		<custom:hidden name="customerinfo"	 property="orgid" changedName="customerid" colIndex="<%=idx%>"/>	
	 					  		<input type="hidden" name="planvisitdate<%=seq%>"	value="<%=strVisitDate%>"/>
	 					  		<input type="hidden" name="splanstarttime<%=seq%>" value="<%=strVisitDate%>"/>		
									<input type="hidden" name="splanendtime<%=seq%>" value="<%=strVisitDate%>"/>	
									<input type="hidden" name="tplanstarttime<%=seq%>" value="<%=strVisitDate%>"/>
									
	 					  	</td>
	 					  	<td><custom:write name="customerinfo"	 property="orgcode"/></td>
	 					  	<td><custom:write name="customerinfo"	 property="orgname"/></td>
	 					  	<td><custom:write name="customerinfo"	 property="globalpcname"/></td>
	 					  	<td>
	 					  	<custom:select  name="customerinfo"	 property="processid"   optionsName="customprocesses" optionValueKey="visitprocessid" optionInnerTextKey="processname"  colIndex="<%=idx%>" defaultValue="---" defaultValueCost=" " />
	 					  	</td>
	 					  	<td>
	 					  	<custom:select  name="customerinfo"	 property="uprocessid"   optionsName="doctorprocesses" optionValueKey="visitprocessid" optionInnerTextKey="processname"  colIndex="<%=idx%>" defaultValue="---" defaultValueCost=" " />
	 					  	</td>
	 					  	<td class="td_right"><%=strVisitDateShow%></td>
	 					  	<td><custom:write name="customerinfo" property="lastvisitdate" nbsp="true" /></td>
							<td><custom:write name="customerinfo" property="count_org" nbsp="true" /></td>
							<td><custom:write name="customerinfo" property="dspotential" nbsp="true" /></td>
							<td><input type="checkbox"  name="showneedassist<%=seq%>"  class="normalradio"  onclick="javascript:page_needassist('<%=seq%>')">
						     <custom:hidden name="customerinfo" property="needassist" colIndex="<%=Integer.valueOf(seq)%>"/>
							</td>
							<td><custom:write name="customerinfo"	 property="attribute"/>&nbsp;</td>	
							 <td>&nbsp;<div id="assistdiv<%=seq%>" >
							 <custom:text name="customerinfo" property="assistemployeename" size="10" colIndex="<%=Integer.valueOf(seq)%>"/>
							 <a onclick="javascript:page_selectUser(<%=seq%>);">
							 <custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0" />
							 <custom:hidden name="customerinfo" property="assistuserid" colIndex="<%=Integer.valueOf(seq)%>"/>
							 </a>
							 </div>
							 </td>
	 					  </tr>
          	 </logic:iterate>
          	<%@ include file="/inc/SummaryAction.inc" %>
          </table>
          <input type="hidden" name="numrows" value="<%=vCustomers.size()%>"/>
        </td>
      </tr>
      <tr>
      	<td>
      		<table width="100%" cellspacing="0" cellpadding="0">
            <tr><td class="summary_top"></td></tr>
            <tr>
              <td class="td_center">
             <a onclick="page_confirm();"><custom:button type="1" label="L_Confirm" imgsrc="new.gif" border="0" style="width:60"/></a>
                
                <a onclick="page_cancel();"><custom:button type="1" label="L_Cancel" imgsrc="Modify.gif" border="0" style="width:60"/></a>
                
               
              </td>
            </tr>
          </table>  
        </td>
      </tr>
    </table>
  </form>  
  <script>
  <%
  java.util.HashMap parentuserinfo = (java.util.HashMap)pageContext.getAttribute("parentuserinfo"); 
  %>
  for(var i=0;i<<%=vCustomers.size()%>;i++){
    if(eval("document.cform.needassist"+i).value=="Y"){
        var div = document.getElementById("assistdiv"+i); 
		div.style.display = 'block';
		<%
		if (parentuserinfo!=null) {
		%>
		 if(isEmpty(eval("document.cform.assistuserid"+i).value)){
		  eval("document.cform.assistuserid"+i).value="<%=parentuserinfo.get("assistuserid")%>";
		  eval("document.cform.assistemployeename"+i).value="<%=parentuserinfo.get("assistemployeename")%>";
		 }
		<%
		}
	    %>
    }else{
        var ndiv = document.getElementById("assistdiv"+i); 
		ndiv.style.display = 'none';

    }
  }
  function page_needassist(seq)
{
	var myform = eval("document.cform");
	var sneedassist=eval("myform.showneedassist"+seq);
	var needassist=eval("myform.needassist"+seq);
	var div = document.getElementById("assistdiv"+seq); 
	if(sneedassist.checked)
	{
		needassist.value="Y";

		div.style.display = 'block';
		<%
		if (parentuserinfo!=null) {
		%>
		 if(isEmpty(eval("document.cform.assistuserid"+seq).value)){
		  eval("document.cform.assistuserid"+seq).value="<%=parentuserinfo.get("assistuserid")%>";
		  eval("document.cform.assistemployeename"+seq).value="<%=parentuserinfo.get("assistemployeename")%>";
		 }
		<%
		}
	    %>
	}
	else{
		needassist.value="N";
		div.style.display = 'none';
	}
}
</script>           	
</body>

</html>
	
